import pandas as pd
import psycopg2
from sqlalchemy import create_engine
import re


def infer_column_type(value):
    try:
        float(value)
        if value.is_integer():
            return 'BIGINT'
        else:
            return 'NUMERIC(10, 2)'
    except ValueError:
        try:
            pd.to_datetime(value)
            return 'TIMESTAMP'
        except ValueError:
            return 'TEXT'


def generate_ddl(file_path, table_name):
    df = pd.read_excel(file_path, nrows=2)
    headers = df.columns
    sample_row = df.iloc[0]
    columns = []
    for header, value in zip(headers, sample_row):
        clean_header = re.sub('[^a-zA-Z0-9_]', '_', header)
        column_type = infer_column_type(value)
        columns.append(f'{clean_header} {column_type}')
    columns_def = ',\n    '.join(columns)
    ddl = f'CREATE TABLE {table_name} (\n    {columns_def}\n);'
    return ddl


if __name__ == '__main__':
    excel_file_path = 'path/to/your/excel/file.xlsx'
    table_name = 'your_table_name'
    ddl = generate_ddl(excel_file_path, table_name)
    print(ddl)